package ar.mobileideas.mobiletasks.app.ui;

import java.util.Hashtable;

import net.rim.device.api.i18n.ResourceBundle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.PasswordEditField;
import net.rim.device.api.ui.container.MainScreen;

import ar.mobileideas.mobiletasks.api.webservice.MobileTasksService;
import ar.mobileideas.mobiletasks.app.main.MobileTasks;
import ar.mobileideas.mobiletasks.app.model.User;
import ar.mobileideas.mobiletasks.resources.resourcesResource;
import ar.mobileideas.mobiletasks.utils.GridFieldManager;

public class LoginScreen extends MainScreen {

	private MobileTasks app;
	private static ResourceBundle _resources = ResourceBundle.getBundle(resourcesResource.BUNDLE_ID,resourcesResource.BUNDLE_NAME);
	
	public LoginScreen() {
		
		setTitle("Login");
		Manager gridFieldManager = new GridFieldManager(new int[] {100, 160}, 30, 0);

		gridFieldManager.add(new LabelField(_resources.getString(resourcesResource.LoginScreenUsername), Field.FIELD_RIGHT | Field.FIELD_VCENTER));
		gridFieldManager.add(new BasicEditField("", "", 200, Field.FIELD_LEFT | Field.FIELD_VCENTER));

		gridFieldManager.add(new LabelField(_resources.getString(resourcesResource.LoginScreenPassword), Field.FIELD_RIGHT | Field.FIELD_VCENTER));
		gridFieldManager.add(new PasswordEditField("", "", 200, Field.FIELD_LEFT | Field.FIELD_VCENTER));

		add(gridFieldManager);
		ButtonField loginButton = new ButtonField(_resources.getString(resourcesResource.LoginScreenLogin));
        
		loginButton.setChangeListener(loginButtonListener);
        this.add(loginButton);
	}
	
	FieldChangeListener loginButtonListener = new FieldChangeListener() {
        
    	public void fieldChanged(Field field, int context) {
    		app = (MobileTasks)UiApplication.getUiApplication();
    		
    		Hashtable parameters = new Hashtable();
    		
    		//String result = MobileTasksService.CallWebServiceMethod("CallHelloWorld", parameters);
    		
    		//Dialog.inform(result);
    		HomeScreen homeScreen = new HomeScreen();
    		
    		app.pushScreen(homeScreen);
        }
    };

}
